package com.cyq.order.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/add")
    public String add() {
        System.out.println("下单成功!");
        String msg = restTemplate.getForObject("http://stock-service/stock/reduct", String.class);
        return "Hello World!" + msg;
    }

    @GetMapping("/header")
    public String header(@RequestHeader("X-Request-red") String header) {
        return header;
    }

    @GetMapping("/header2")
    public String header2(@RequestHeader("X-Request-Red") String header) {
        return header;
    }
}
